<?php

namespace Common\Model;

/**
 * Description of HotelRoomCostModel
 * 
 * @author wenhui
 * @date wenhui 2017-12-19
 * @index hotelId(`hotelentity_id`)
 */
class HotelRoomCostModel extends BaseModel {

    protected $trueTableName = 'tb_hotel_room_cost';

    /**
     * 添加数据
     * @modify wenhui 2017-12-19
     * @param array $data 封装好的信息
     * @return boolean          执行结果
     */
    public function addInfo($hotelId, $name) {

        $data = array(
            'hotelentity_id' => $hotelId,
            'name' => $name,
        );

        $result = $this->add($data);
        return empty($result) ? false : $result;
    }

    /**
     * 修改数据
     * @modify wenhui 2017-12-19
     * @param inetegr $hotelId
     * @param string $costId 
     * @param integer $name
     */
    public function saveInfo($hotelId, $costId, $name) {
        $options = array(
            'hotelentity_id' => $hotelId,
            'id' => $costId,
        );
        $data['name'] = $name;

        $result = $this->where($options)->save($data);
        return $result === false ? false : true;
    }


    /**
     * 获取数据
     * @modify wenhui 2017-12-19
     * @param  integer   $hotelId   客栈ID
     * @return array        信息数组
     */
    public function getRoomCostInfoByHotel($hotelId) {
        if (is_array($hotelId)) {
            $option['hotelentity_id'] = array('in', $hotelId);
        } else {
            $option['hotelentity_id'] = $hotelId;
        }

        $data = $this->where($option)->select();
        return empty($data) ? array() : $data;
    }

    /**
     * 删除条目
     * @modify wenhui 2017-12-19
     * @param  integer   $hotelId        客栈id
     * @param  integer   $costId 条目id
     * @return mixin                   删除结果
     */
    public function deleteCheckRoom($hotelId, $costId) {
        $option = array(
            'hotelentity_id' => $hotelId,
            'isdelete' => NOT_DELETE,
            'id' => $costId,
        );
        $data = array(
            'isdelete' => IS_DELETE,
        );
        return $this->where($option)->save($data) === false ? false : true;
    }
}
